﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using BitsDownloadMgr.Interop;
using VMDS.Business.Entities;

namespace VMDS.GUIClient.Model
{
    internal static class BitsUtility
    {
        private static CopyManager _copyManager = new CopyManager();

        /// <summary>
        /// Global instance of the CopyManager for the current process.
        /// </summary>
        public static CopyManager CopyManager
        {
            get
            {
                return _copyManager;
            }
        }
        public static void showBitsError(System.Runtime.InteropServices.COMException ex, string addlInfo)
        {
            MessageBox.Show("The operation failed with HResult " + ex.ErrorCode.ToString("X") + "\n" + addlInfo);
        }

        public static bool ForegroundPresent()
        {
            return _copyManager.GetJobs().Any(job => (job.DisplayName == "VMDS_VM") && (job.Priority==BitsJobPriority.Foreground));
        }

        public static CopyJob GetVmJob(VM vm)
        {
            return _copyManager.GetJobs().FirstOrDefault(job => (job.DisplayName == "VMDS_VM") && (job.Description == vm.Id.ToString()));
        }
    }
}
